package com.cloudcc.cloudframe.net.async;

import com.cloudcc.cloudframe.bus.IDataEvent;
import com.cloudcc.cloudframe.net.ErrorInfo;
import com.litesuits.android.log.Log;

import de.greenrobot.event.EventBus;

/**
 * @Description: 事件的请求
 * @author wangzhiqiang
 * @date 2015-11-24 下午2:48:18
 * 
 * @param <T>
 */
public class EventRequest<T> extends GenericsRequest<T> {

	protected IDataEvent<T> mEvent;

	public void setEvent(IDataEvent<T> event) {
		this.mEvent = event;
	}

	@Override
	public void handleSuccess(T data) {
		if (mEvent != null) {
			mEvent.setData(data);
			mEvent.setOk(true);
			Log.d("zoudaolenali", "發送數據");
			EventBus.getDefault().post(mEvent);
		}
	}

	@Override
	public void handleFailure(ErrorInfo e) {
		if (mEvent != null) {
			mEvent.setOk(false);
			mEvent.setMessage(e.getErrorMessage());
			EventBus.getDefault().post(mEvent);
		}
	}

}
